package com.xxx.video.mine.presenters;

import android.content.Context;

import androidx.annotation.NonNull;

import com.xxx.video.commen.dbs.beans.SearchHistoryBean;
import com.xxx.video.commen.dbs.utils.DbUtils;
import com.xxx.video.commen.presenters.BasePresenter;
import com.xxx.video.commen.utils.ResponseUtils;
import com.xxx.video.mine.beans.SearchHotWordListBean;
import com.xxx.video.network.listeners.CommonResponseListener;
import com.xxx.video.network.utils.NetWorkUtils;

import java.util.List;

public class SearchRecommendPresenter extends BasePresenter<ISearchRecommendView> {

    public SearchRecommendPresenter(@NonNull Context context, ISearchRecommendView baseView) {
        super(context, baseView);
    }

    /**
     * get history key word
     */
    public void getHistoryKeyword() {
        NetWorkUtils.getInstance().getHistoryKeyword(new CommonResponseListener<SearchHotWordListBean>() {
            @Override
            public void onSuccess(SearchHotWordListBean successOb, String result) {
                if (getBaseView() != null) {
                    getBaseView().showRootLayoutStatus(1);
                }
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().initSearchHotWordListBeanData2View(successOb);
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {
                if (getBaseView() != null) {
                    getBaseView().showRootLayoutStatus(1);
                }
            }
        });

    }

    /**
     * get search history list
     */
    public void getSearchHistoryList() {
        List<SearchHistoryBean> searchHistoryBeanList = DbUtils.getInstance().getSearchHistoryList();
        if (getBaseView() != null) {
            getBaseView().initSearchHistoryListData2View(searchHistoryBeanList);
        }
    }
}
